// PGLBoxPlot.cpp: implementation of the CPGLBoxPlot class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "include/pgl.h"
#include "include/PGLLine.h"
#include "include/PGLBoxPlot.h"
#include "include/DataRegistry.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

PGL_IMPLEMENT_DYNCREATE(CPGLBoxPlot, CPGLLine);

void CPGLBoxPlot::SerializeXML(CPGLArchive& ar)
{
	CString strPos;	strPos.Format(_T("%u"),(DWORD)this);
	static const TCHAR szTag[] = _T("CPGLBoxPlot");

	markup::CMarkupArchive& xml = *((markup::CMarkupArchive*)ar.GetMarkup());
	if(ar.IsStoring())
	{
		xml.AddChildElem(szTag);
		xml.IntoElem();

			/////////////////////////////////////////////////////////
			// Adding base class
			CPGLLine::SerializeXML(ar);

			xml.AddChildElemEx(_T("BoxWidth"), m_fBoxWidth);
			xml.AddChildElemEx(_T("ColumnSize"), m_stColumnSize);
			xml.AddChildElemEx(_T("Values"));
			xml.IntoElem();
				m_pData->SerializeXML(ar);
			xml.OutOfElem();

				
		xml.OutOfElem();
	}
	else
	{
		if  (!xml.FindChildElem(szTag))
				return;



		xml.IntoElem();
			CPGLLine::SerializeXML(ar);

			xml.FindGetChildData( _T("BoxWidth"), m_fBoxWidth);
			xml.FindGetChildData(_T("ColumnSize"), m_stColumnSize);
			PGL_SERIALIZE_LOAD_DATA( strPos , Values , m_pData );

		xml.OutOfElem();
	}
}


#ifdef _DEBUG
void CPGLBoxPlot::Dump( CDumpContext& dc ) const
{
    // call base class function first
    CPGLLine::Dump( dc );
}
void CPGLBoxPlot::AssertValid() const
{
    // call inherited AssertValid first
    CPGLLine::AssertValid();

} 
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPGLBoxPlot::CPGLBoxPlot()
{

}

CPGLBoxPlot::~CPGLBoxPlot()
{

}

void CPGLBoxPlot::SetBoxWidth( float fBoxWidth )
{	
	m_fBoxWidth = fBoxWidth;
};

float CPGLBoxPlot::GetBoxWidth() const			
{	
	return m_fBoxWidth;
};

void CPGLBoxPlot::SetData( CPGLDataPtr pData, size_t stColumnSize )
{
	m_pData = pData;
	m_stColumnSize = stColumnSize;
};

CPGLDataPtr CPGLBoxPlot::GetData() const
{	
	return m_pData;
};

void CPGLBoxPlot::ClearData()
{
	m_pData.reset();
};

size_t CPGLBoxPlot::GetColumnSize() const			
{	
	return m_stColumnSize;
};



void CPGLBoxPlot::GetUnionExtent(gfxinterface::CGfxInterface& gfx, CPGLRectD& rExtent)
{
	CPGLObject::GetUnionExtent(gfx,rExtent);

	GetExtent().SetUnion(rExtent);

	rExtent.xValid = rExtent.yValid=(m_pData.get() != NULL);
}

void CPGLBoxPlot::UpdateExtent(gfxinterface::CGfxInterface& gfx)
{
	CPGLLine::UpdateExtent(gfx);
	size_t ileft, iright;

	if (!m_pData)
	{
		SetExtent( CPGLRectD::GetNormBox());
		return;
	}

	size_t nPoints=m_pData->size();
	if (nPoints == 0)
	{
		SetExtent( CPGLRectD::GetNormBox() );
		return;
	}

	// updating...
	CPGLRectD rExtent;

	rExtent.left=-1;
	rExtent.right=GetColumnCount()+1;
	m_pData->GetMinMaxIndex(ileft, iright);
	rExtent.bottom = m_pData->at(ileft);
	rExtent.right = m_pData->at(iright);

	// setting extent
	SetExtent(rExtent);
}


size_t CPGLBoxPlot::GetColumnCount() const
{
	if (!m_pData)
		return 0;

	return m_pData->size() / m_stColumnSize;
};

void CPGLBoxPlot::PlotLineStripGfx(gfxinterface::CGfxInterface& gfx)
{
	if (!m_pData)
		return;

}

void CPGLBoxPlot::PlotPointStripGfx(gfxinterface::CGfxInterface& gfx)
{}

void CPGLBoxPlot::PlotArrowsGfx(gfxinterface::CGfxInterface& gfx)
{}
